<?php 
require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_sub_menu.php";
require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_menu.php";

$sub_menu_access = new dao_sub_menu();
$menu_access = new dao_menu();

?>
<nav>
    <div class="menubg">
        <div id="navigation">
            <div class="chromestyle" id="chromemenu">
                <ul>
                    <?php
                    $menus = $menu_access->get_all();
                    foreach ($menus as $item) {
                        $sub_menus = $sub_menu_access->get_all_by_menu_key($item['menu_key']);
                        $menu_action = LINK_ROOT.'/dynamic_content.php?menu_id=' . $item['menu_id'];
                        
                        $constant_sub_menus = array();
                        if ($item['menu_key']==='publication') {
                            $constant = array();
                            $constant['action'] = LINK_ROOT . "/journal.php";
                            $constant['title'] = "Journals";
                            $constant_sub_menus[sizeof($constant_sub_menus)] = $constant;
                            
                            $constant = array();
                            $constant['action'] = LINK_ROOT . "/working_papers.php";
                            $constant['title'] = "Working Papers";
                            $constant_sub_menus[sizeof($constant_sub_menus)] = $constant;
                            
                            $constant = array();
                            $constant['action'] = LINK_ROOT . "/briefing_papers.php?year=".date("Y");
                            $constant['title'] = "Briefing Papers";
                            $constant_sub_menus[sizeof($constant_sub_menus)] = $constant;
                            
                            $menu_action = LINK_ROOT . "/journal.php";
                        } else if ($item['menu_key']==='conference') {
                            $menu_action = LINK_ROOT . "/conference.php";
                        } else if ($item['menu_key']==='news') {
                            $menu_action = LINK_ROOT . "/news_list.php";
                        }
                    ?>
                    <li><a href="<?php echo $menu_action; ?>" <?php if (!empty($sub_menus) || !empty($constant_sub_menus)){echo 'rel="' . $item['menu_key'] . '"';} ?>><?php echo $item['menu_title']; ?></a></li>
                    <?php if (!empty($sub_menus) || !empty($constant_sub_menus)) { ?>
                    <div id="<?php echo $item['menu_key']; ?>" class="dropmenudiv">
                        <?php
                            foreach ($constant_sub_menus as $sub_item) {
                                echo "<a href='" . $sub_item['action'] . "'>" . $sub_item['title'] . "</a>";
                            }
                            foreach ($sub_menus as $sub_item) {
                                $param = '?sub_menu_id=' . $sub_item['sub_menu_id'];
                                echo "<a href='" . LINK_ROOT . "/dynamic_content.php" . $param . "'>" . $sub_item['title'] . "</a>";
                            }
                        ?>
                    </div>
                    <?php
                        }
                    }
                    ?>
                </ul>
            </div>
            
            
            <script type="text/javascript">
                cssdropdown.startchrome("chromemenu");
            </script>
        </div>
    </div>
</nav>
<?php
?>
<!--
<nav id='cssmenu'>
    <ul>
        <li><a href="<?php echo LINK_ROOT.'/'; ?>index.php"><span>Home</span></a></li>
        <li class="has-sub"><a href="<?php echo LINK_ROOT.'/'; ?>our_team.php" rel="dropmenu1"><span>Our Team</span></a>
            <ul>
                <li>
                    <a href="<?php echo LINK_ROOT.'/'; ?>internal_aduirory_board.php">
                        <span>The Chairman's Message</span>
                    </a>
                </li>
                <li>
                    <a href="<?php echo LINK_ROOT.'/'; ?>advisory_board.php">
                        <span>Advisory Board</span>
                    </a>
                </li>
                <li class="last">
                    <a href="<?php echo LINK_ROOT.'/'; ?>administrative_team.php">
                        <span>Administrative Team</span>
                    </a>
                </li>
            </ul>
        </li>
        <li class='has-sub'><a href="<?php echo LINK_ROOT.'/'; ?>publication.php" rel="dropmenu2"><span>Publication</span></a>
            <ul>
                <li>
                    <a href="<?php echo LINK_ROOT.'/'; ?>publication.php">
                        <span>Journals</span>
                    </a>
                </li>
                <li class="last">
                    <a href="<?php echo LINK_ROOT.'/'; ?>working_papers.php">
                        <span>Working Papers</span>
                    </a>
                </li>
            </ul>
        </li>
        <li><a href="<?php echo LINK_ROOT.'/'; ?>social_development.php"><span>Social Development</span></a></li>
        <li><a href="<?php echo LINK_ROOT.'/'; ?>hrd.php"><span>HRD</span></a></li>
        <li class='has-sub'><a href="<?php echo LINK_ROOT.'/'; ?>seminars_training.php" rel="dropmenu3"><span>Seminars & Training</span></a>
            <ul>
                <li>
                    <a href="<?php echo LINK_ROOT.'/'; ?>training_programs.php">
                        <span>Workshops & Training</span>
                    </a>
                </li>
                <li class="last">
                    <a href="<?php echo LINK_ROOT.'/'; ?>instractor.php">
                        <span>Instructor</span>
                    </a>
                </li>
            </ul>
        </li>
        <li><a href="<?php echo LINK_ROOT.'/'; ?>news.php"><span>News</span></a></li>
        <li class='last'><a href="<?php echo LINK_ROOT.'/'; ?>contact_us.php"><span>Contact Us</span></a></li>
    </ul>
</nav>
-->